//
//  LGHeartRhythmRecordCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/31.
//  心律监测 - 历史记录

#import "LGHeartRhythmRecordCell.h"

@interface LGHeartRhythmRecordCell()

/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UIButton *tipButton;
/**   */
@property (nonatomic , strong)UILabel *rateLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGHeartRhythmRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.baseView.backgroundColor = [UIColor colorWithString:@"#F5FBFF"];
        [self createSubView];
    }
    return  self;
}

-(void)setType:(LGPositionType)type{
    [super setType:type];
    CGFloat bottom = (type == LGPositionTypeBottom)?-viewPix(25):-viewPix(8);
    [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView).offset(bottom);
    }];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    self.timeLabel.text = LGNSString(dataDic[@"record_time"]);
    self.tipButton.selected = [dataDic[@"ecg_warm"] integerValue]>0?YES:NO;
    NSString *boardColor = [dataDic[@"ecg_warm"] integerValue]>0?@"#FB670D":@"#5E8EF5";
    self.tipButton.layer.borderColor = [UIColor colorWithString:boardColor].CGColor;
    NSString *warm = LGNSString(dataDic[@"ecg_warm"]);
    if ([warm isEqualToString:@"2"]) {
        self.rateLabel.text = @" ";
    }else{
        NSString *content = [NSString stringWithFormat:@"平均心率 %@ 次/分钟",dataDic[@"ecg"]];
        self.rateLabel.attributedText = [content attributeString:@{NSFontAttributeName:LGFont(16) , NSForegroundColorAttributeName:[UIColor colorWithString:@"#282828"]} range:NSMakeRange(5, LGNSString(dataDic[@"ecg"]).length)];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.tipButton];
    [self.contentView addSubview:self.rateLabel];
    [self.contentView addSubview:self.tipView];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.top.equalTo(self.contentView).offset(viewPix(10));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    [self.tipButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeLabel.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.timeLabel);
        make.width.equalTo(@(viewPix(56)));
        make.height.equalTo(@(viewPix(18)));
    }];
    [self.rateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(50));
        make.centerY.equalTo(self.timeLabel);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.centerY.equalTo(self.timeLabel);
        make.width.height.equalTo(@(16));
    }];
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UIButton *)tipButton{
    if(!_tipButton){
        _tipButton = [UIButton buttonWithTitle:@"未见异常" titleFont:LGFontWeight(12, UIFontWeightBold) normalColor:@"#5E8EF5" selectColor:@"#FB670D"];
        [_tipButton setSelectTitle:@"干扰数据" textColor:@"#FB670D"];
        [_tipButton setBackgroundColor:@"#F5FBFF" selectColor:@"#FEF5F0"];
        [_tipButton addBorder:@"#5E8EF5" lineWidth:1 cornerRidus:5];
        _tipButton.userInteractionEnabled = NO;
    }
    return _tipButton;
}

-(UILabel *)rateLabel{
    if(!_rateLabel){
        _rateLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _rateLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
    }
    return _tipView;
}
@end
